<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/11/22
  Time: 9:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>产品列表</title>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap/js/jquery-2.1.0.js"></script>
</head>
<body>
    <div style="background-color:#f5fafe;width: 100%;height: 100%">
        <%--产品列表显示--%>
        <div class="row">
            <c:forEach var="p" items="${p.pageList}">
                <div class="col-xs-2">
                    <div class="thumbnail">
                        <img src="${pageContext.request.contextPath}/${p.image}" alt="..." style="height: 20%">
                        <div class="caption">
                            <h5 style="overflow: hidden;text-overflow:ellipsis;white-space: nowrap">${p.pname}</h5>
                            <p>市场价：${p["market_price"]}</p>
                            <p>是否热销：
                                <c:if test="${p[\"is_hot\"] eq 1}">是</c:if><%--eq：相等--%>
                                <c:if test="${p[\"is_hot\"] eq 0}">否</c:if>
                            </p>
                                <%--
                                    双引号的转义：${c[\"is_hot\"]}
                                --%>
                            <p><a href="${pageContext.request.contextPath}/editUIProduct?pid=${p.pid}" class="btn btn-primary btn-sm" role="button">修改</a> <a href="${pageContext.request.contextPath}/deleteProduct?pid=${p.pid}" onclick="return confirm('确认是否删除')" class="btn btn-default btn-sm" role="button">删除</a></p>
                        </div>
                    </div>
                </div>
            </c:forEach>
        </div>
        <%--分页查询栏--%>
        <hr>
        <div>
        第${p.page}页/共${p.pageCount}页
        <%--页码处理--%>
        <c:choose>
            <%--当显示页码时,总页码<=10时，全部显示--%>
            <c:when test="${p.pageCount<=10}">
                <c:set var="begin" value="1"/>
                <c:set var="end" value="${p.pageCount}"/>
            </c:when>
            <%--当总页码>10时,只显示10页--%>
            <c:otherwise>
                <c:set var="begin" value="${p.page-5}"/>
                <c:set var="end" value="${p.page+4}"/>
                <%--当前页-5后的begin<1时：begin=1, end=10--%>
                <c:if test="${begin<1}">
                    <c:set var="begin" value="1"/>
                    <c:set var="end" value="10"/>
                </c:if>
                <%--当前页+4后的end>总页数时:begin=总页数-9,end=总页数--%>
                <c:if test="${end>p.pageCount}">
                    <c:set var="begin" value="${p.pageCount-9}"/>
                    <c:set var="end" value="${p.pageCount}"/>
                </c:if>
            </c:otherwise>
        </c:choose>
        <%--样式及显示--%>
        <nav aria-label="...">

            <ul class="pagination">
                <li><a href="${pageContext.request.contextPath}/adminProduct?page=1">首页</a></li>

                <%--上一页--%>
                <c:if test="${p.page>1}">
                    <li class="">
                        <a href="${pageContext.request.contextPath}/adminProduct?page=${p.page-1}" aria-label="Previous">
                            <span aria-hidden="true">&laquo;</span></a>
                    </li>
                </c:if>

                <%--<li class="active"><a href="#">1 <span class="sr-only">(current)</span></a></li>--%>
                <c:forEach var="num" begin="${begin}" end="${end}">
                    <%--显示页码时，是当前页，则不显示超链接--%>
                    <c:choose>
                        <c:when test="${num==p.page}"><%--ne:不等于--%>
                            <li class="active">
                                <span>${num}<span class="sr-only">(current)</span></span><%--a标签改为span标签--%>
                            </li>
                        </c:when>
                        <c:otherwise>
                            <li class="">
                                <a href="${pageContext.request.contextPath}/adminProduct?page=${num}">${num} <span class="sr-only">(current)</span></a>
                            </li>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>

                <%--当前页面为最后一页时不显示下一页--%>
                <c:if test="${p.page<p.pageCount}">
                    <li>
                        <a href="${pageContext.request.contextPath}/adminProduct?page=${p.page+1}" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                </c:if>

                <li><a href="${pageContext.request.contextPath}/adminProduct?page=${p.pageCount}">尾页</a></li>
            </ul>
        </nav>
    </div>
</div>


</body>
</html>
